package lanou.autohome.find;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;

/**
 * Created by dllo on 16/8/23.
 */
public class FindAdapter extends RecyclerView.Adapter<FindAdapter.FindViewHolder> {

    private FindBean findBean;
    private Context mcontext;

    public FindAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setFindBean(FindBean findBean) {
        this.findBean = findBean;
    }

    @Override
    public FindViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_find_recyclerview_caini , null);
        FindViewHolder findViewHolder = new FindViewHolder(view);
//        View view = null;
//        FindViewHolder holder = null;
//        switch (viewType){
//            case 0:
//                view = LayoutInflater.from(mcontext).inflate(R.layout.item_find_recyclerview_caini , parent , false);
//                holder = new FindViewHolder(view);
//                break;
//            case 1:
//                view = LayoutInflater.from(mcontext).inflate(R.layout.item_find_recyclerview_weiwo , parent , false);
//                holder = new FindViewHolder(view);
//                break;
//        }

        return findViewHolder;
    }

    @Override
    public void onBindViewHolder(FindViewHolder holder, int position) {

        FindBean.ResultBean.ModulelistBean.ListBean listBean = findBean.getResult().getModulelist()
                .get(0).getList().get(position);

        holder.title.setText(listBean.getTitle());
        holder.shorttitle.setText(listBean.getShorttitle());
        holder.price.setText(String.valueOf(listBean.getPrice()));
        holder.fctprice.setText(String.valueOf(listBean.getFctprice()));

        NetTool netTool = new NetTool();
        netTool.getImage(listBean.getLogo(), holder.logo);

    }

    @Override
    public int getItemCount() {
        return findBean != null ? 4 : 0;
    }

//    @Override
//    public int getItemViewType(int position) {
//        if (modulelistBeans.getTitle() == "猜你喜欢") {
//            return TYPE_ONE;
//        } else if (modulelistBeans.getTitle() == "为我推荐") {
//            return TYPE_TWO;
//        }
//        return position;
//    }
    public class FindViewHolder extends RecyclerView.ViewHolder {

        TextView title;
        TextView shorttitle;
        TextView price;
        TextView fctprice;
        ImageView logo;

        public FindViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title_caini_find_recyclerview);
            shorttitle = (TextView) itemView.findViewById(R.id.shorttitle_caini_find_recyclerview);
            price = (TextView) itemView.findViewById(R.id.price_caini_find_recyclerview);
            fctprice = (TextView) itemView.findViewById(R.id.frcprice_caini_find_recyclerview);
            logo = (ImageView) itemView.findViewById(R.id.imageview_caini_find_recyclerview);
        }
    }
}
